package org.lzy.shop.order

import com.google.android.material.tabs.TabLayoutMediator
import org.lzy.shop.Constant
import org.lzy.shop.R
import org.lzy.shop.adapter.MyOrderFragAdapter
import org.lzy.shop.base.BaseActivity
import org.lzy.shop.databinding.ActivityMyOrderBinding

/**
 * 我的订单
 */
class MyOrderActivity: BaseActivity<ActivityMyOrderBinding>({ ActivityMyOrderBinding.inflate(it) }) {

     private var adapter: MyOrderFragAdapter? = null

    override fun initView() {
        setTitleText(getResString(R.string.my_order))
    }

    override fun initData() {
        try {
            if (intent.extras != null) {
                val bundle = intent.extras
                //当前用户选择哪个tab
                fragemntPosition = bundle!!.getInt(Constant.ORDER_POSITION)
            }
            adapter = MyOrderFragAdapter(this@MyOrderActivity)
            binding.viewPager.setAdapter(adapter)
            //不带丝滑动的显示当前item
            binding.viewPager.setCurrentItem(fragemntPosition, false)
            //注意下tablayout显示中英文不要放在最上面，因为放上面因控件没有初始化导致无法获取文本, 所以放在控件后面
            val  mTitles = listOf(resources.getString(R.string.order_all), resources.getString(R.string.pending_payment),
                resources.getString(R.string.deliver), resources.getString(R.string.receiving), resources.getString(R.string.order_tab_refund),
                resources.getString(R.string.order_comment), resources.getString(R.string.order_finish))
            TabLayoutMediator(binding.tablayout,binding.viewPager) {
           tab, position -> tab.text = mTitles[position]
            }.attach()


        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun requestData() {
    }

    override fun allClick() {

    }

    companion object {
        var fragemntPosition: Int = 0
    }
}